//手机验证
function checkPhone() {
	if (isEmptyNo($("#mobile").val())) { 
		$("#mobile").attr("class","mobile");
		$("#mobile").attr("placeholder","手机号不能为空");
		return false;
	} 
	var reg=/^1[3,4,5,7,8]\d{9}$/;
	if (!reg.test($("#mobile").val())&&$("#mobile").val()!="") { 
		$("#mobile").val("");
		$("#mobile").attr("class","mobile");
		$("#mobile").attr("placeholder","手机号格式不正确");
		return false;
	}return true;
}

function checkName(){
	if(isEmptyNo($('#carOwnerName').val())){
		$("#carOwnerName").attr("class","carOwnerName");
		$("#carOwnerName").attr("placeholder","姓名不能为空");
		return false;
	}
	var reg = /^[\u4E00-\u9FA5]+$/;
	if(!reg.test($("#carOwnerName").val())){
		$("#carOwnerName").val("");
		$("#carOwnerName").attr("class","carOwnerName");
		$("#carOwnerName").attr("placeholder","请输入中文姓名");
		return false;
	}
	if($("#carOwnerName").val().length<2){
		$("#carOwnerName").val("");
		$("#carOwnerName").attr("class","carOwnerName");
		$("#carOwnerName").attr("placeholder","姓名至少大于一个汉字");
		return false;
	} return true;
}
function checkEngineNo(){
	if(isEmptyNo($('#engineNo').val())){
		$("#engineNo").attr("class","engineNo");
		$("#engineNo").attr("placeholder","发动机号不能为空");
		return false;
	} return true;
}
function checkFrameNo(){
	if(isEmptyNo($('#frameNo').val())){
		$("#frameNo").attr("class","frameNo");
		$("#frameNo").attr("placeholder","发动机号不能为空");
		return false;
	} return true;
}
function checkLicenseNo(){
	if(isEmptyNo($('#licenseNo').val())){
		$("#licenseNo").attr("class","licenseNo");
		$("#licenseNo").attr("placeholder","车牌号不能为空");
		return false;
	}
	var s = $('#licenseNo').val();
	var reg=/^[\u4E00-\u9FA5][\da-zA-Z]{6}$/;
	if(!reg.test(s)){
		$("#licenseNo").val("");
		$("#licenseNo").attr("class","licenseNo");
		$("#licenseNo").attr("placeholder","车牌号错误");
		return false;
	} return true;
}

//身份证号
function checkIdNo(){
	var idCard=$('#identifyNumber').val();
	if(isEmptyNo(idCard)){
		$("#identifyNumber").val("");
		$("#identifyNumber").attr("class","identifyNumber");
		$("#identifyNumber").attr("placeholder","身份证号码不能为空");
		return false;
	}
	//15位和18位身份证号码的正则表达式
	var regIdCard=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
	//如果通过该验证，说明身份证格式正确，但准确性还需计算
	 if(regIdCard.test(idCard)){
		  if(idCard.length==18){
			 var idCardWi=new Array( 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ); //将前17位加权因子保存在数组里
			 var idCardY=new Array( 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ); //这是除以11后，可能产生的11位余数、验证码，也保存成数组
			 var idCardWiSum=0; //用来保存前17位各自乖以加权因子后的总和
			 for(var i=0;i<17;i++){
				 idCardWiSum+=idCard.substring(i,i+1)*idCardWi[i];
			 }
			 var idCardMod=idCardWiSum%11;//计算出校验码所在数组的位置
			 var idCardLast=idCard.substring(17);//得到最后一位身份证号码
			 //如果等于2，则说明校验码是10，身份证号码最后一位应该是X
			 if(idCardMod==2){
				 if(idCardLast=="X"||idCardLast=="x"){
					 return true;
				 }else{
					 $("#identifyNumber").val("");
					 $("#identifyNumber").attr("class","identifyNumber");
					 $("#identifyNumber").attr("placeholder","请输入有效的身份证!");
					 return false;
				 }
			 }else{
				 //用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
				 if(idCardLast==idCardY[idCardMod]){
					 return true;
				 }else{
					 $("#identifyNumber").val("");
					 $("#identifyNumber").attr("class","identifyNumber");
					 $("#identifyNumber").attr("placeholder","请输入有效的身份证!");
					 return false;
				 }
			 }
		 } 
	 }else{
		$("#identifyNumber").val("");
		$("#identifyNumber").attr("class","identifyNumber");
		$("#identifyNumber").attr("placeholder","身份证格式不正确!");
		return false;
	 }
}
function onfocusLicenseNo(){
	$("#licenseNo").removeAttr("class");
//	$("#licenseNo").attr("style","color:black");
	$("#licenseNo").attr("placeholder","如沪123543");
}
function onfocusPhone(){
	$("#mobile").removeAttr("class");
//	$("#car_user_phone").attr("style","color:black");
	$("#mobile").attr("placeholder","请输入您的手机号");
}

function onfocusName(){
	$("#carOwnerName").removeAttr("class");
//	$("#car_user_name").attr("style","color:black");
	$("#carOwnerName").attr("placeholder","请输入车主姓名");
}
function onfocusIdentifyNumber(){
	$("#identifyNumber").removeAttr("class");
	$("#identifyNumber").attr("placeholder","请输入身份证号");
}
function onfocusEngine(){
	$("#engineNo").removeAttr("class");
//	$("#car_user_name").attr("style","color:black");
	$("#engineNo").attr("placeholder","请输入发动机号");
}
function onfocusFrame(){
	$("#frameNo").removeAttr("class");
//	$("#car_user_name").attr("style","color:black");
	$("#frameNo").attr("placeholder","请输入车架号");
}
function onfucusVerify(){
	$("#verify_content").removeAttr("class");
	//$("#verify_content").attr("style","color:black;");
	$("#verify_content").attr("placeholder","请输入验证码");
}
//邮箱
function isEmailNo(email){
	var regEmail=/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+(\.[a-zA-Z]{2,3})+$/;
	if(regEmail.test(email)){
	   return true;
	}else{
	   return false;
	}
}
//非空
function isEmptyNo(empty){
	if(empty.trim().length<1){
		  return true;
	}else{
		  return false;
	}
}